package com.example.myapplication;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class Sign_up3 extends AppCompatActivity {

    private EditText username_txt;
    private EditText password_txt;
    private EditText passagain_txt;

    private String username_sign;
    private String password_sign;
    private String passagain;
    private   Button btn_clear;
    private   Button btn_signin;


    @SuppressLint("MissingInflatedId")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_sign_up3);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });


        username_txt = findViewById(R.id.editText_user_sign);
        password_txt = findViewById(R.id.editText_pass_sign);
        passagain_txt = findViewById(R.id.editText_passagain);


       Button btn_signin = findViewById(R.id.button_signin);


        //注册按钮

        btn_signin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                username_sign = username_txt.getText().toString();
                password_sign = password_txt.getText().toString();
                passagain = passagain_txt.getText().toString();

                if (!password_sign.equals(passagain)){
                    Toast.makeText(getApplicationContext(),"两次密码不一致，请重新输入！",Toast.LENGTH_SHORT).show();
                    password_txt.setText("");
                    passagain_txt.setText("");
                    password_txt.requestFocus();
                }else{
                    Intent intent = new Intent(getApplicationContext(),Sing_in3.class);
                    intent.putExtra("user",username_sign);
                    intent.putExtra("pass",password_sign);
                    startActivity(intent);
                    finish();
                }

            }
        });
      btn_clear =findViewById(R.id.button_clear);
      btn_clear.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              password_txt.setText("");
              username_txt.setText("");
              passagain_txt.setText("");
              username_txt.requestFocus();

          }
      });



    }
}